package com.springboot.astra.config;

import com.springboot.astra.myInterceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    TokenInterceptor getTokenInterceptor(){
        return new TokenInterceptor();
    }
//    @Bean
//    AdminInterceptor getAdminInterceptor(){
//        return new AdminInterceptor();
//    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册token拦截器，获取spring容器里的bean
        InterceptorRegistration registrationToken = registry.addInterceptor(getTokenInterceptor());
        registrationToken.addPathPatterns("/**");
        registrationToken.excludePathPatterns(
                                        "/index/userLogin",              //用户登录
                                        "/index/adminLogin",
                                        "/static/**",
                                        "/**/error",
                                        "/favicon.ico"
                                        );
    }
}
